#include<iostream>
using namespace std;
#include<vector>
#include<queue>
class Solution {
public:
    int dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 };
    int m, n;
    int search(vector<vector<int>>& grid, int x, int y) {
        queue<pair<int, int>> que;
        que.push({ x,y });
        grid[x][y] = 0;
        int ans = 0;
        while (que.size()) {
            ++ans;
            int a = que.front().first, b = que.front().second;
            for (int i = 0; i < 4; ++i) {
                int x0 = a + dx[i], y0 = b + dy[i];
                if (x0 >= 0 && x0 < m && y0 >= 0 && y0 < n && grid[x0][y0]) {
                    que.push({ x0,y0 });
                    grid[x0][y0] = 0;
                }
            }
            que.pop();
        }
        return ans;
    }
    int maxAreaOfIsland(vector<vector<int>>& grid) {
        m = grid.size(), n = grid[0].size();
        int ans = 0;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                if (grid[i][j])
                    ans = max(ans, search(grid, i, j));
            }
        }
        return ans;
    }
};
int main() {
    vector<vector<int>> vec{ {1,1,0,0,0},{1,1,0,0,0},{0,0,0,1,1},{0,0,0,1,1} };
    Solution().maxAreaOfIsland(vec);
}